﻿using Architecture.API.Application.Command.CityCommand;
using Architecture.Domain;
using Architecture.Domain.Service.CityServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.CityHandler
{
    /// <summary>
    /// 城市搜索命令处理器
    /// </summary>
    public class CitySearchCommandHandler : IRequestHandler<CitySearchCommand, List<City>>
    {
        /// <summary>
        /// 城市服务
        /// </summary>
        private readonly ICityService _cityService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="cityService">城市服务</param>
        public CitySearchCommandHandler(ICityService cityService)
        {
            _cityService = cityService;
        }

        /// <summary>
        /// 获取城市列表
        /// </summary>
        /// <param name="request">请求到的省份ID</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回城市列表</returns>
        public async Task<List<City>> Handle(CitySearchCommand request, CancellationToken cancellationToken)
        {
            return await _cityService.GetAllAsync(request.ProvinceId);
        }
    }
}
